﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Lenovo.CFI.Common;
using Lenovo.CFI.Common.Sys;
using Lenovo.CFI.DAL.Sys;
using Lenovo.CFI.DAL;
using Lenovo.CFI.Common.Mail;

using NPOI.HSSF.UserModel;
using NPOI.HPSF;
using NPOI.POIFS.FileSystem;
using NPOI.SS.UserModel;
using System.IO;

namespace Lenovo.CFI.BLL.Sys
{
    public class UserBl
    {
        public User GetUserByItCode(string itcode)
        {
            return UserDa.GetUserByItCode(itcode);
        }


        public List<User> GetUserByItCodes(params string[] itcodes)
        {
            return UserDa.GetUserByItCode(itcodes);
        }

        public List<User> GetUserWithRole(int role)
        {
            return UserDa.GetUserWithRole(role);
        }


        public List<User> GetUserAll()
        {
            return UserDa.GetUserAll();
        }

        public List<User> GetUser(string itcode, int? teamID, string manager, string vp, bool? enabled, int? permLevel)
        {
            if (itcode == String.Empty) itcode = null;

            return UserDa.GetUser(itcode, teamID, manager, vp, enabled, permLevel);
        }


        public void EditUser(User user)
        {
            UserDa.UpdateUser(user);
        }


        public ICollection<string> GetUserDynamicRole(string itcode)
        {
            int rolesValue = UserDa.GetUserDynamicRole(itcode);

            List<string> roles = new List<string>();

            if ((rolesValue & UserRole.ROLE_MGR) == UserRole.ROLE_MGR) roles.Add(UserRole.ROLE_MGR.ToString());
            if ((rolesValue & UserRole.ROLE_VP) == UserRole.ROLE_VP) roles.Add(UserRole.ROLE_VP.ToString());
            if ((rolesValue & UserRole.ROLE_TDC) == UserRole.ROLE_TDC) roles.Add(UserRole.ROLE_TDC.ToString());
            if ((rolesValue & UserRole.ROLE_DC) == UserRole.ROLE_DC) roles.Add(UserRole.ROLE_DC.ToString());
            if ((rolesValue & UserRole.ROLE_IP) == UserRole.ROLE_IP) roles.Add(UserRole.ROLE_IP.ToString());
            if ((rolesValue & UserRole.ROLE_REVIEWER) == UserRole.ROLE_REVIEWER) roles.Add(UserRole.ROLE_REVIEWER.ToString());
            if ((rolesValue & UserRole.ROLE_EXECUTOR) == UserRole.ROLE_EXECUTOR) roles.Add(UserRole.ROLE_EXECUTOR.ToString());

            return roles;
        }
    }
}
